<?php
class QSource_System_Controller_Permission extends Zend_Controller_Plugin_Abstract
{
		protected $_acl;
		public function __construct($acl){
			$this->_acl = $acl;
		}
		public function preDispatch(Zend_Controller_Request_Abstract $res){
			$auth = Zend_Auth::getInstance();
			$role = "Guest";
			if($auth->hasIdentity()){
				$info = $auth->getIdentity();
				$level = QSource_System_Models_WebmasterRole::getNamebyId($info->role);
				if(!empty($level))
					$role = $level;
				$module = $res->getModuleName();
				$controller = $res->getControllerName();
				$action = $res->getActionName();
				if($module == "administrator")
				{
					if(!$this->_acl->isAllowed($role, $module.':'.$controller, $action)){
						if($role!="Guest"){
							$res->setModuleName("administrator")
								->setControllerName("index")
								->setActionName("noaccess");
						}else{
							$res->setModuleName("administrator")
								->setControllerName("login")
								->setActionName("index");
						}
					} 
				}
			}
		}
}